package socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;

public class SocketClient {

	public static void main(String[] args) {
		try {
			Socket socket = new Socket("localhost", 1444);
			Thread.sleep(5000);
			System.out.println("isConnected: " + socket.isConnected());
			System.out.println("isClosed: " + socket.isClosed());
			System.out.println("isInputShutdown: " + socket.isInputShutdown());
			System.out.println("isOutputShutdown: " + socket.isOutputShutdown());
			PrintWriter w = new PrintWriter(socket.getOutputStream());
			w.print("hello");
			w.flush();
			BufferedReader r = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			socket.setSoTimeout(20000);
			System.out.println(r.readLine());
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
